package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2022/3/22 11:57
 * @description：https://leetcode-cn.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/
 */
public class 如果相邻两个颜色均相同则删除当前颜色 {
    @Test
    public void test() {
        Solution solution = new Solution();
    }

    class Solution {
        public boolean winnerOfGame(String colors) {
            int[] sum = {0, 0};
            char tmp = 'C';
            int cnt = 0;
            for (int i = 0; i < colors.length(); i++) {
                char c = colors.charAt(i);
                if (c != tmp) {
                    tmp = c;
                    cnt = 1;
                } else {
                    cnt++;
                    if (cnt >= 3) {
                        sum[c - 'A']++;
                    }
                }
            }
            return sum[0] > sum[1];
        }
    }
}
